package stu.day19_day24.day21;

public class LeetCode34 {
    public int[] searchRange(int[] nums, int target) {
        if(nums.length==0){
            return new int[]{-1,-1};
        }

        int left = 0;
        int right = nums.length;
        int mid;
        while (left<right){
            mid = (left+right)/2;
            if(nums[mid]>=target){
                right = mid;
            } else if (nums[mid]<target){
                left = mid+1;
            }
        }
        int num1 = left;

        left = 0;
        right = nums.length;
        while (left<right){
            mid = (left+right)/2;
            if(nums[mid]>target){
                right = mid;
            } else if (nums[mid]<=target){
                left = mid+1;
            }
        }
        int num2 = left-1;

        if(num2<0){
            return new int[]{-1,-1};
        }
        else if(nums[num2]==target){
            return new int[]{num1,num2};
        }else {
            return new int[]{-1,-1};
        }


    }
}
